package com.hhy.hhy_weibo.controller;

import com.auth0.jwt.JWT;
import com.hhy.hhy_weibo.mapper.UmsUserMapper;
import com.hhy.hhy_weibo.model.domain.UmsUser;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;

public class BaseController {
    @Autowired
    private UmsUserMapper userMapper;

    @Autowired
    private HttpServletRequest request;

    /**
     * 根据token获取用户信息
     * @return user
     */
    public UmsUser getUser() {
        String token = request.getHeader("token");
        String aud = JWT.decode(token).getAudience().get(0);
        Integer userId = Integer.valueOf(aud);
        return userMapper.selectById(userId);
    }
}
